﻿using Bilibili.Model.Parts;
using System;
using System.Collections.Generic;

namespace Bilibili.Model.Video
{
    public sealed class VideoInfoModels
    {
        public int Code { get; set; }
        public string Message { get; set; }
        public VideoInfoModels Data { get; set; }
        public string Aid { get; set; }
        public string Attribute { get; set; }
        public int CopyRight { get; set; }
        public long? Ctime { get; set; }
        public string Desc { get; set; }
        public long? Duration { get; set; }
        public string Pic { get; set; }
        public long? PubDate { get; set; }
        public int State { get; set; }
        public string Title { get; set; }
        public int Tid { get; set; }
        public string Tname { get; set; }
        public string Redirect_Url { get; set; }
        public OwnerModel Owner { get; set; }
        public OwnerExtModel Owner_Ext { get; set; }
        public List<PagesModel> Pages { get; set; }
        public int PartCount => Pages == null ? 0 : Pages.Count;
        public List<RelatesModel> Relates { get; set; }
        public ReqUserModel Req_User { get; set; }
        public RightsModel Rights { get; set; }
        public SeasonModel Season { get; set; }
        public List<TagsModel> Tag { get; set; }
        public StatModel Stat { get; set; }
        public MovieModel Movie { get; set; }
        public ElecModel Elec { get; set; }
        public AudioModel Audio { get; set; }
        public List<StaffModel> Staff { get; set; }
        public InteractionModel Interaction { get; set; }
        public string CreatedAt
        {
            get
            {
                DateTime dtStart = new DateTime(1970, 1, 1, 0, 0, 0);
                long lTime = long.Parse(PubDate + "0000000");
                TimeSpan toNow = new TimeSpan(lTime);
                DateTime dt = dtStart.Add(toNow).ToLocalTime();
                TimeSpan span = DateTime.Now - dt;
                if (span.TotalDays > 7)
                    return dt.ToString();
                else if (span.TotalDays > 1)
                    return string.Format("{0}天前", (int)Math.Floor(span.TotalDays));
                else if (span.TotalHours > 1)
                    return string.Format("{0}小时前", (int)Math.Floor(span.TotalHours));
                else if (span.TotalMinutes > 1)
                    return string.Format("{0}分钟前", (int)Math.Floor(span.TotalMinutes));
                else if (span.TotalSeconds >= 1)
                    return string.Format("{0}秒前", (int)Math.Floor(span.TotalSeconds));
                else
                    return "1秒前";
            }
        }
    }
}